<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace app\blog\controller;

use app\admin\model\UserModel;
use app\blog\model\BusinessModel;
use app\blog\model\StoreModel;
use App\Http\Model\Home\goods;
use cmf\controller\AdminBaseController;
use think\Db;
class MemberController extends AdminBaseController
{
    public function index(){

        return $this->fetch();
    }

    function datum(){
        //陶康修改，时间：2018-5-7   17:04
        $adminid = cmf_get_current_admin_id();
        $shopid = Db::name('user')->where('id='.$adminid)->find();
        $list = Db::name('member')->where('1=1')->alias('a')->join('__STORE__ b','a.store_id=b.id','left')->field('a.*,b.store_name')->order('id desc')->select();
        $this->assign('list',$list);
        return $this->fetch();
    }

    function del(){
        $param = $this->request->param();
        $param=$param['idnumber'];
       //var_dump($param);exit;
        DB::name('member')->where('idnumber',$param)->delete();
        $this->success('删除成功');
        //return redirect('store/add');
    }

    function recharge(){
        //会员充值记录查询
       $cc= DB::name('recharge')
            ->alias('r')
            ->join('member m','m.id=r.userid')
            ->join('store s','s.id=r.storeid')
            ->join('user u','u.id=r.operatorid')
            ->select();
        //var_dump($cc);exit;
        $this->assign('cc',$cc);
       return $this->fetch();
    }

    function consume(){
        //会员消费记录查询
        return $this->fetch();
    }

    function edit(){
        $param = $this->request->param();
        $paramt=$param['idnumber'];
       $member=DB::name('member')->where('idnumber',$paramt)->select();
        $this->assign('member',$member);
        //var_dump($member[0]['store_id']);exit;
        $store_name=DB::name('store')->column('store_name');
        $this->assign('store_name',$store_name);
        //var_dump($store_name);exit;

        return $this->fetch('edit');
    }

    function edit2(){
        if($this->request->isPost()){
            $data=$this->request->Post();
            $param = $this->request->param();
            $param=$param['id'];
            $store_id=DB::name('store')->where('store_name',$data['store_id'])->column('id');

            $data['store_id']=$store_id;
            //var_dump($data['store_id']);exit;
            if($data['sex']='男'){
                $data['sex']=1;

            }elseif($data['sex']='女'){
                $data['sex']=2;
            }

            DB::name('member')->where('id', $param)->update($data);
            $this->success('更新成功',url('member/datum'));



        }
    }








}
























